package trasisgestion.servlet.usuario;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.javafx.scene.layout.region.Margins.Converter;

import trasisgestion.excepcion.DAOExcepcion;
import trasisgestion.negocio.GestionUsuarios;

/**
 * Servlet implementation class for Servlet: UsuarioInsertarServlet
 * 
 */
@WebServlet("/UsuarioInsertarServlet")
public class UsuarioInsertarServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
	static final long serialVersionUID = 1L;

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public UsuarioInsertarServlet() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 * HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 * HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

	
		Integer i = Integer.parseInt(request.getParameter("idusuario")); 				
		String ii = request.getParameter("nombres");
		String iii= request.getParameter("paterno");
		String iv = request.getParameter("materno");
		String v = request.getParameter("sexo");
		String vi = request.getParameter("documento");
		String vii = request.getParameter("nrodocumento");
		String viii = request.getParameter("correo");
		String ix = request.getParameter("celular");
		String x = request.getParameter("clave");
		Integer xi = Integer.parseInt(request.getParameter("tipo"));
		Integer xii = Integer.parseInt(request.getParameter("centro"));
		
		GestionUsuarios negocio = new GestionUsuarios();
		try {
			negocio.insertar(i, ii, iii, iv, v, vi, vii, viii, ix, x, xi, xii);
			response.sendRedirect(request.getContextPath()	+ "/UsuarioBuscarServlet");
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}

	}
}